package managedbean.Employee; 
 
import entity.Employee;
import java.io.IOException;
import java.io.Serializable;
import java.util.List; 
import javax.ejb.EJB; 
import javax.faces.bean.ManagedBean; 
import javax.faces.bean.ViewScoped; 
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import session.stateless.EmployeeBeanLocal; 
 
@ManagedBean(name="viewEmployeeManagerBean")
@ViewScoped 
public class ViewEmployeeManagerBean implements Serializable { 
    @EJB 
    private EmployeeBeanLocal employeeSessionBeanLocal; 
    private Employee selectedEmployee;
 
    public ViewEmployeeManagerBean() { } 
    public List<Employee> getEmployees() { 
        return employeeSessionBeanLocal.getEmployees(); 
    }

    public Employee getSelectedEmployee() {
        return selectedEmployee;
    }
    public void setSelectedEmployee(Employee selectedEmployee) {
        this.selectedEmployee = selectedEmployee;
    }
        
    public void editEmployee(ActionEvent event) throws IOException{
        Employee selectedEmployee = this.getSelectedEmployee();
        System.out.println("getEmployee"+selectedEmployee.getEmployeeName());
        if (selectedEmployee != null){
            FacesContext.getCurrentInstance().getExternalContext().getFlash().put("selectedEmployee", selectedEmployee);            
            FacesContext.getCurrentInstance().getExternalContext().redirect("editEmployee.xhtml");                
        }
    }    

    public void deleteEmployee(ActionEvent event) throws IOException{
        Employee selectedEmployee = this.getSelectedEmployee();
        if (selectedEmployee != null){
            FacesContext.getCurrentInstance().getExternalContext().getFlash().put("selectedEmployee", selectedEmployee);            
            FacesContext.getCurrentInstance().getExternalContext().redirect("deleteEmployee.xhtml");                
        }
    }     
} 
